#!/bin/bash

SERVICE_PREFIX=aug-
HARBOR=harbor.augmentum.com.cn
PROJECT_NAME=smartconstruction
VERSION_NUMBER=11
DOCKER_NAME=platform-
SERVICE_PREFIX=aug



# cleanCmd="docker rm -f ${DOCKER_NAME} > /dev/null 2>&1 && echo 'removed container' || echo 'nothing to remove'; \
# docker rmi --force \\`docker images | grep ${DOCKER_NAME}  | awk '{print $3}\'\\`> /dev/null 2>&1 "
# sshpass -p "abc123_" ssh -o StrictHostKeyChecking=no user@172.20.249.18 "$cleanCmd"


  cleanCmd="docker rm -f ${DOCKER_NAME} > /dev/null 2>&1 && echo 'removed container' || echo 'nothing to remove' ; \
  docker rmi --force \`docker images | grep ${DOCKER_NAME} | awk '{print \$3}' \` > /dev/null 2>&1&& echo 'removed images' || echo 'nothing to remove' "
  sshpass -p "abc123_" ssh -o StrictHostKeyChecking=no user@192.168.4.241 "$cleanCmd"

# docker rmi --force `docker images | grep vuejs-docker  | awk '{print $3}'` > /dev/null 2>&1

# cd /home/user/deploy-smartconstruction

# cd /home/user/Aug-git/smartconstruction/platform-backend
# exist=`docker-compose -p middleware -f /home/user/Aug-git/smartconstruction/platform-backend/docker-compose-middleware.yml ps|grep Up`&&echo ${exist}
# if [ -n "${exist}" ]; then echo "skipping...middleware service is running."; \
# else docker-compose -f docker-compose-middleware.yml -p middleware down; \
# docker-compose -f docker-compose-middleware.yml -p middleware up -d; fi

# 原始脚本
# cd /home/user/deploy-${PROJECT_NAME}; \
# exist=`docker-compose -f docker-compose-middleware.yml -p middleware ps|grep Up`&&echo "$exist";if [ -n "$exist" ]; then echo 'skipping...middleware service is running.'; \
# else echo 'middleware service NOT EXIST; start middleware services....';\
#     docker-compose -f docker-compose-middleware.yml -p middleware down; \
#     docker-compose -f docker-compose-middleware.yml -p middleware up -d; fi

# cd /home/user/deploy-${PROJECT_NAME}; \
# if [ `docker-compose -f docker-compose-middleware.yml -p middleware ps|grep Up|wc -l` -le 0 ]; then docker-compose -f docker-compose-middleware.yml -p middleware down&&docker-compose -f docker-compose-middleware.yml -p middleware up -d; fi


# cd /home/user/deploy-${PROJECT_NAME}; \
# if [ -n `docker-compose -f docker-compose-middleware.yml -p middleware ps|grep Up` ]; then echo 'skipping...middleware service is running.'; \
#                   else echo 'middleware service NOT EXIST; start middleware services....';\
#                   docker-compose -f docker-compose-middleware.yml -p middleware down; \
#                   docker-compose -f docker-compose-middleware.yml -p middleware up -d; fi


# num=`docker-compose -f docker-compose-middleware.yml -p middleware ps|grep Up|wc -l`; \
# [[ `docker-compose -f docker-compose-middleware.yml -p middleware ps|grep Up|wc -l` -le 0 ]]&& docker-compose -f docker-compose-middleware.yml -p middleware down&&docker-compose -f docker-compose-middleware.yml -p middleware up -d


# [[ $? -eq 0 ]] && echo "backup $i success" || exit


# cd /home/user/Aug-git/group-jenkins-pipeline/global-shared-library/vars
# sshpass -p "${SERVER_ACCESS_KEY_PSW}" ssh -o StrictHostKeyChecking=no ${SERVER_ACCESS_KEY_USR}@${DEPLOY_SERVER} "$middlewareCmd"

# echo "$middlewareCmd"

# sshpass -p "abc123_" ssh -o StrictHostKeyChecking=no user@172.20.249.5 "${middlewareCmd}"



